package com.gxar.marketdelivery.interfaces.assembler;

import com.gxar.marketdelivery.infra.dao.entity.DeliveryRuleEntity;
import com.gxar.marketdelivery.shared.model.DeliveryRuleModel;
import com.gxar.marketdelivery.shared.model.PeriodModel;
import com.gxar.marketdelivery.shared.utils.AssemblerUtils2;
import com.gxar.marketdelivery.shared.utils.JacksonUtils;
import com.gxar.marketdelivery.shared.utils.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @author nice
 * @version 1.0
 * @created 2023/7/24.
 */
public class DeliveryPlanConverter {
    public static DeliveryRuleModel convertToRuleModel(DeliveryRuleEntity ruleEntity) {
        DeliveryRuleModel ruleModel = new DeliveryRuleModel();
        AssemblerUtils2.assemble(ruleEntity, ruleModel);
        ruleModel.setPeriodModels(convertToPeriodModel(ruleEntity.getPeriodInfo()));
        return ruleModel;
    }

    public static List<PeriodModel> convertToPeriodModel(String periodInfo) {
        if (StringUtils.isEmpty(periodInfo)) {
            return Collections.emptyList();
        }
        return JacksonUtils.parseList(periodInfo, PeriodModel.class);
    }
}
